package com.awspaas.user.apps.cpq.controller;

import java.util.HashMap;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.BOCopyAPI;
import com.actionsoft.sdk.local.api.BOQueryAPI;

public class CPQ_GetNewComponentWeb {

	public String getNewComponent(UserContext userContext, String bindId, String type) {
		try {
			BOQueryAPI dataQuery=SDK.getBOAPI().query("BO_EU_CPQ_COMPONENT_PART").bindId(bindId);
			BOQueryAPI gridsQuery=SDK.getBOAPI().query("BO_EU_CPQ_COMPONENT_PART_GRID").bindId(bindId);
			BOQueryAPI propertiesQuery=SDK.getBOAPI().query("BO_EU_CPQ_COMPONENT_PART_PROPERTIES_GRID").bindId(bindId);
			BOQueryAPI priceQuery=SDK.getBOAPI().query("BO_EU_BO_EU_CPQ_COMPONENT_PART_USER_PRICE_GRID").bindId(bindId);
			BOQueryAPI outsourcingQuery=SDK.getBOAPI().query("BO_EU_CPQ_COMPONENT_PART_OUTSOURCING_GRID").bindId(bindId);
			//创建新的物料单价数据
			String pid=SDK.getProcessAPI().createBOProcessInstance("obj_191624b652f041c1a21bba93fd88b319",userContext.getUID(), "").getId();
			BOCopyAPI newData=dataQuery.copyTo("BO_EU_CPQ_COMPONENT_PART", pid);
//			if(type.equals("创建新模块")) {
//				newData.addNewData("MKBM","");
//				newData.addNewData("BBH","V1.0");
//				newData.addNewData("VERSION","1");
//			}else if(type.equals("创建新版本")) {
//				BO bo=dataQuery.detail();
//				String vString=bo.getString("VERSION");
//				int num=Integer.valueOf(vString);
//				int newNum=num+1;
//				newData.addNewData("BBH","V"+newNum+".0");
//				newData.addNewData("VERSION",newNum);
//			}
//			
			
			newData.addNewData("STATUS","拟制");
			newData.addNewData("BM","");
			//newData.addNewData("CJLX",type);
			newData.exec();
			BOCopyAPI newGrids=gridsQuery.copyTo("BO_EU_CPQ_COMPONENT_PART_GRID", pid);
			newGrids.exec();
			BOCopyAPI newParameter=propertiesQuery.copyTo("BO_EU_CPQ_COMPONENT_PART_PROPERTIES_GRID", pid);
			newParameter.exec();
			BOCopyAPI newPrice=priceQuery.copyTo("BO_EU_BO_EU_CPQ_COMPONENT_PART_USER_PRICE_GRID", pid);
			newPrice.exec();
			BOCopyAPI newOutsourcing=outsourcingQuery.copyTo("BO_EU_CPQ_COMPONENT_PART_OUTSOURCING_GRID", pid);
			newOutsourcing.exec();
			//SDK.getBOAPI().query("").bindId(bindId);
			ResponseObject ro = ResponseObject.newOkResponse();
			Map<String, String> map=new HashMap<String, String>();
			map.put("bindId", pid);
			ro.setData(map);
			return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
